﻿using Microsoft.AspNetCore.Connections;

namespace sgf.server
{
    public class TcpConnectionHandler(
        Action<NetChannel> onConnect,
        Action<long, byte[]> onMessage,
        Action<NetChannel> onDisConnect) : ConnectionHandler
    {
        public override async Task OnConnectedAsync(ConnectionContext connection)
        {
            LogMgr.Debug($"{connection.RemoteEndPoint} 连接成功");
            NetChannel channel = new TcpChannel(connection, onMessage);
            onConnect(channel);
            await channel.StartAsync();
            LogMgr.Debug($"{channel.remoteAddress} 断开链接");
            onDisConnect(channel);
        }
    }
}